package yxy.game.pm2.active.command.monthcard;

import yxy.cherry.data.bean.actprivilege;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.ActiveModule_月卡;
import yxy.game.pm2.active.module.actdata.ActDataCenter;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;
import yxy.game.pm2.message.ActiveMessage.ActMonthCardInfoRequest;

@MessageType(proto = Command.ActMonthCardInfo, classtype = ActiveMessage.ActMonthCardInfoRequest.class)
public class CMD_Active_月卡_Info extends Command<ActMonthCardInfoRequest> {

	@Override
	public void execute(MessageSource messageSource, ActMonthCardInfoRequest request) throws Exception {
		String pcode = messageSource.getTag();
		
		ActiveMessage.ActMonthCardInfoResponse.Builder response = ActiveMessage.ActMonthCardInfoResponse.newBuilder();
		
		ActiveModule_月卡 am = ActiveModule_月卡.get(pcode,false);
		if(am == null) {
			send(messageSource, response, Result.DataError);
			return;
		}
		
		actprivilege ap1 = ActDataCenter.getData(ActiveModule_月卡.monthcard1, actprivilege.class, pcode);
		actprivilege ap2 = ActDataCenter.getData(ActiveModule_月卡.monthcard2, actprivilege.class, pcode);
		if(ap1 == null || ap2 == null) {
			send(messageSource, response, Result.DataError);
			return;
		}
		
		response.setVipmcreward(am.cangetvipmcreward());
		
		{
			ActiveMessage.MonthCardInfo.Builder mc1 = ActiveMessage.MonthCardInfo.newBuilder();
			int condition1 = ap1.getCondition();
			mc1.setGroup(ActiveModule_月卡.monthcard1);
			mc1.setStarttime(am.getMc1starttime().getMillis());
			mc1.setEndtime(am.getMc1endtime().getMillis());
			mc1.setVipexp(am.getMc1payexp());
			mc1.setGetdays(am.getMc1getdays());
			mc1.setCondition(condition1);
			mc1.setRebate(ap1.getRebate()); //返利倍数
			mc1.setCanget(am.canmcreward(ActiveModule_月卡.monthcard1));
			response.addMcs(mc1);
		}

		{
			ActiveMessage.MonthCardInfo.Builder mc2 = ActiveMessage.MonthCardInfo.newBuilder();
			int condition2 = ap2.getCondition();
			mc2.setGroup(ActiveModule_月卡.monthcard2);
			mc2.setStarttime(am.getMc2starttime().getMillis());
			mc2.setEndtime(am.getMc2endtime().getMillis());
			mc2.setVipexp(am.getMc2payexp());
			mc2.setGetdays(am.getMc2getdays());
			mc2.setCondition(condition2);
			mc2.setRebate(mc2.getRebate()); //返利倍数
			mc2.setCanget(am.canmcreward(ActiveModule_月卡.monthcard2));
			response.addMcs(mc2);	
		}
		
		send(messageSource, response, Result.Success);
	}

	
	private void send(MessageSource messageSource, ActiveMessage.ActMonthCardInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
	
}
